package com.times.demo.controller;


import com.times.demo.common.Result;
import com.times.demo.entity.UserEntity;
import com.times.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/save")
    public String addUser(UserEntity userEntity) {
        userService.save(userEntity);
        return "success";
    }

    @GetMapping("/list")
    public String list(){
        List<UserEntity> list = userService.list();

        // 判断手机号是否符合规则
        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";

        // 返回用户列表
        return list.toString();
    }


    @GetMapping("selectById")
    public <T> Result selectById(String id){
        UserEntity userEntity = new UserEntity();
        userEntity.setCreateTime(new Date());
        userEntity.setUpdateBy("123");
        userEntity.setCreateBy("234");
        return Result.success(userEntity);
    }

}
